//
// Created by qinf on 2025/7/27.
//
#include "udp.h"
#include "generateData.h"
#include <iostream>

int main() {
    std::cout << "Client started..." << std::endl;
    ClientUDP client, client1, client2;
    //改为目标IP
    client.setip_add(10001, (char*)"127.0.0.1");  // 任务分配数据
    client1.setip_add(10002, (char*)"127.0.0.1");  // 航点数据
    client2.setip_add_multi(10003, (char*)"227.0.0.1");  // 侦察目标数据

    int count_all = 0;
    auto start = std::chrono::system_clock::now();
    while (1)
    {
        //发送数据
        auto TaskData = generateTaskData();
        client.sendData(TaskData.data(), TaskData.size());
        auto waypointData = generateWaypointData();
        client1.sendData(waypointData.data(), waypointData.size());//
        auto TargetData = generateTargetData();
        client2.sendData(TargetData.data(), TargetData.size());
        //灌包测试
        count_all = count_all + 1;
        std::cout << "count_all : " << count_all << std::endl;

        auto now = std::chrono::system_clock::now();
        auto durtion = now - start;
        auto mill = std::chrono::duration_cast<std::chrono::milliseconds>(durtion);
        std::cout << "Time cost : " << mill.count() << std::endl;

        // 发送速率调节//延迟//帧率50//帧率100
        // std::this_thread::sleep_for(std::chrono::milliseconds(20));
        // std::this_thread::sleep_for(std::chrono::microseconds(20000)); //约50Hz
        std::this_thread::sleep_for(std::chrono::microseconds(10));
    }

    return 0;
}
